import isKeyword from 'is-keyword-js';
import jsTokens, { matchToToken } from 'js-tokens';
/**
 * 将逻辑表达式解释为 Tokens
 * @param {string} code
 * @return {Object[]}
 */

var esTokenizer = function esTokenizer(code) {
  var tokens = code.match(jsTokens).map(function (value) {
    jsTokens.lastIndex = 0;
    return matchToToken(jsTokens.exec(value));
  }).map(function (token) {
    if (token.type === 'name' && isKeyword(token.value)) {
      // eslint-disable-next-line no-param-reassign
      token.type = 'keyword';
    }

    return token;
  });
  return tokens;
};

export default esTokenizer;